package com.github.shiqiyue.app.api.sapi.controller.app;

/***
 *
 * @author wenyao.wu
 */

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.shiqiyue.app.api.sapi.common.SApiBaseController;
import com.github.shiqiyue.app.common.enums.DeletedEnum;
import com.github.shiqiyue.app.common.req.BasePageReq;
import com.github.shiqiyue.app.common.result.Result;
import com.github.shiqiyue.app.common.result.SimplePageResult;
import com.github.shiqiyue.app.modules.app.entity.CommonIndex;
import com.github.shiqiyue.app.modules.app.entity.Position;
import com.github.shiqiyue.app.modules.app.service.ICommonIndexService;
import com.github.shiqiyue.app.modules.app.service.IPositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("sapi/app/commonIndex")
public class SApiCommonIndexController extends SApiBaseController {

    @Autowired
    private ICommonIndexService commonIndexService;

    @PostMapping("page")
    public Result page(BasePageReq pageReq) {
        IPage<CommonIndex> resultPage = commonIndexService.page(pageReq);
        SimplePageResult<CommonIndex> result = new SimplePageResult();
        result.setPageInfo(resultPage);
        result.setRecords(resultPage.getRecords());
        return Result.success(result);
    }

    @PostMapping("add")
    public Result add(CommonIndex commonIndex) {
        commonIndexService.save(commonIndex);
        return Result.success();
    }

    @PostMapping("edit")
    public Result edit(CommonIndex commonIndex) {
        commonIndexService.updateById(commonIndex);
        return Result.success();
    }


    @PostMapping("detail")
    public Result detail(Long id) {
        return Result.success(commonIndexService.getById(id));
    }

}
